package com.smmisia.shop.handler;

import com.smmisia.common.Result.Result;
import com.smmisia.common.exception.BizException;
import com.smmisia.shop.exception.ProductException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result<String> handleException(Exception e) {
        // 处理异常并返回响应
        return Result.fail("系统异常:" + e.getMessage());
    }

    @ExceptionHandler(ProductException.class)
    public Result<String> handleSQLIntegrityConstraintViolationException(ProductException e) {
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler(BizException.class)
    public Result<String> biz(BizException e) {
        return Result.fail(e.getMessage());
    }
}